package com.cz.nongyetongv5.activity;

import android.app.Activity;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.drawable.BitmapDrawable;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.widget.ImageView;

import com.cz.nongyetongv5.R;
import com.cz.nongyetongv5.bean.AdvBean;

public class AdvActivity extends Activity {

	private ImageView ivImageView = null;

	private AdvBean advBean = null;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.welcome);

		ivImageView = (ImageView) findViewById(R.id.welcomeImage);

		advBean = (AdvBean) getIntent().getSerializableExtra("adv");

		if (advBean != null && advBean.getBitmapByte() != null) {

			Bitmap bitmap = BitmapFactory.decodeByteArray(
					advBean.getBitmapByte(), 0, advBean.getBitmapByte().length);
			ivImageView.setBackgroundDrawable(new BitmapDrawable(bitmap));

		}

		Handler handler = new Handler() {
			public void dispatchMessage(Message msg) {
				switch (msg.what) {
				case 999:
					Intent intent = new Intent(AdvActivity.this,
							(Class<?>) getIntent().getExtras().getSerializable(
									"to"));

					intent.putExtras(getIntent().getExtras());

					startActivity(intent);

					AdvActivity.this.finish();

					break;
				}
			}
		};

		handler.sendEmptyMessageDelayed(999, 2 * 1000);

	}

	@Override
	public void onBackPressed() {
		super.onBackPressed();
	}
}
